//付款页数据
let buy_data = {
    //获取保存的订单时间和总价数据
    orderTime: localStorage.getItem('orderTime'),
    allPrice: localStorage.getItem('allPrice'),
};
//获取保存的地址id
let aid = localStorage.getItem('address');

let order_info = document.querySelector('.order_info');
//根据地址id获取地址
ajax({
    url: '/user/addressById',
    type: 'get',
    data: aid,
    success: function(data) {
        data = JSON.parse(data)[0];
        buy_data.address = data;
        order_info.innerHTML = template('buy_info',buy_data);
        // console.log(buy_data.address);
    },
    error: function(e){
        console.log(e);
    }
});
//a标签选中效果
let as = document.querySelectorAll('.play>a');
for (let a of as) {
    a.addEventListener('click',function(){
        let a_active = document.querySelector('.play>a.active');
        if(a_active){
            a_active.classList.remove('active');
        }
        this.classList.add('active');
    });
}

//当点击按钮触发事件
let btn = document.querySelector('.btn>button');
btn.addEventListener('click',function(){
    //支付修改订单状态
    if(confirm('确认支付')){
        let uid = localStorage.getItem('uid');
        ajax({
            url: '/user/order_update',
            type: 'post',
            data: `status=2&orderTime=${buy_data.orderTime}&uid=${uid}`,
            success: function(data) {
                alert('支付成功，等待发货！');
                location.replace('/');
            },
            error: function(e){
                console.log(e);
            }
        });
    }
});